#    Supsta
#    Copyright (c) 2014 Sebastian Dufner
#
#    This file is part of Supsta.
#
#    Supsta is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Supsta is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

module Supsta
  module Gimp
    class Drawable
      def initialize(application, layer)
        @app, @self = application, layer
      end

      def copy!
        @app.script.concat "(gimp-edit-copy #{@self})\n"

        nil
      end

      def paste
        var = @app.new_var
        @app.script.concat "(define #{var} (car(gimp-edit-paste #{@self} 1)))\n"

        Layer.new(@app, var)
      end

      def invert
        @app.script.concat "(gimp-invert #{@self})\n"

        self
      end

      def clear
        @app.script.concat "(gimp-edit-clear #{@self})\n"

        self
      end

      def to_s
        @self.to_s
      end

      def fill(*rgb)
        @app.set_foreground(*rgb[0, 3]) unless rgb.empty?
        @app.script.concat "(gimp-edit-fill #{@self} 0)\n"

        self
      end

    end
  end
end
